/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.verify.constraint;


// TODO: Refactor to use EqualUtil
public class DifferentTo extends ModifiableConstraint<DifferentTo> {
	private final Object differentTo;
	private final Stringer stringer;
	private final EqualTo equalTo;

	public DifferentTo(Object differentTo, Modifier modifier, Stringer stringer) {
		super(modifier);

		this.differentTo = differentTo;

		this.stringer = stringer; 

		this.equalTo = new EqualTo(differentTo, modifier, stringer);
	}

	public boolean matches(Object differentTo) {
		return this.differentTo.equals(differentTo);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Equal methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	@Override
	public boolean equalTo(DifferentTo differentTo) {
		return differentTo.matches(this.differentTo);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Constraint methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public boolean evaluate(Object value) {
		return !equalTo.evaluate(value);
	}

	@Override
	public String describeFailureImpl() {
		return "is not different to <" + toString(differentTo) + ">";
	}
	
	protected String toString(Object value) {
		return stringer.toString(	value);
	}

	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public int hashCode() {
		return differentTo.hashCode();
	}

	@Override
	public String toString() {
		return "Is different to: " + differentTo;
	}
}
